package com.zs4sdk.entity;

import org.json.JSONException;
import org.json.JSONObject;

import com.common.library.util.Helper;

/**
 * 
 * function: 广告json返回结果
 * 
 * @ author: aXiBa
 */
public class AdsJSONResultEntity extends BaseJSONEntity {
	//#region 静态成员变量
	
	// 类型
	public static final int TYPE_BANNER = 0;
	public static final int TYPE_WINDOW = 1;

	// JSON key
	public static final String COLUMN_TYPE = "type";
	private static final String COLUMN_URL = "url";
	public static final String COLUMN_IMG = "img";

	//#endregion 静态成员变量

	//#region 成员变量
	
	/**
	 * 用户编号
	 */
	private int type;
	/**
	 * 注册成功后自动登录，登录成功标识
	 */
	private String url;
	/**
	 * 昵称
	 */
	private String img;
	
	
	
	//#endregion Getter & Setter集

	//#region 接口声明

	//#endregion 接口声明

	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getImg() {
		return img;
	}
	public void setImg(String img) {
		this.img = img;
	}
	//#region 构造方法
	/**
	 * 构造方法
	 */
	public AdsJSONResultEntity(){
		
	}
	/**
	 * 构造方法
	 * @param json
	 */
	public AdsJSONResultEntity(JSONObject json){
		this.fromJSON(json);
	}
	/**
	 * 构造方法
	 * @param jsonStr
	 */
	public AdsJSONResultEntity(String jsonStr){
		try{
			this.fromJSON(new JSONObject(jsonStr));
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public AdsJSONResultEntity(AdsJSONResultEntity entity){
		this.type = entity.getType();
		this.img = entity.getImg();
		this.url = entity.getUrl();
	
	}
	//#endregion 构造方法

	//#region Override方法

	@Override
	public JSONObject toJSON() {
		JSONObject result = new JSONObject();
		try {
			result.put(COLUMN_TYPE, this.type)
				  .put(COLUMN_IMG, this.img)
				  .put(COLUMN_URL, this.url)
				  ;
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	@Override
	public void fromJSON(JSONObject json) {
		
		if (Helper.isNotEmpty(json)){
			this.type = json.optInt(COLUMN_TYPE);
			this.img = json.optString(COLUMN_IMG);
			this.url = json.optString(COLUMN_URL);
		}
	}
}
